<template>
	<view class="uni-common-pb uni-padding-wrap uni-common-mt">
		<view class="content">
			<text class="title0">{{subtitle}}</text>
		</view>


		<view class="uni-form-item uni-row">
			<view class="title">工单编号</view>
			<view class="title">{{workordernumber}}</view>
		</view>

		<view class="uni-form-item uni-row">
			<view class="title">产品品号</view>
			<view class="title">{{productname}}</view>
		</view>

		<view class="uni-form-item uni-row">
			<view class="title">全长</view>
			<view class="title">{{fulllength}}</view>
		</view>

		<view class="uni-form-item uni-row">
			<view class="title">规格名</view>
			<view class="title">{{specname}}</view>
		</view>

		<view class="uni-form-item uni-row">
			<view class="title">发料记录</view>
			<view class="title">{{issuerecord}}</view>
		</view>

		<view class="uni-form-item uni-row">
			<view class="title">备注</view>
			<view class="title">{{info}}</view>
		</view>

		<view class="line-item"></view>

		<view class="uni-form-item uni-row">
			<view class="title">状态</view>
			<view class="title">序号</view>
			<view class="title">代号</view>
			<view class="title">名称</view>
			<view class="title">良品</view>
			<view class="title">不良</view>
			<view class="title">原料不良</view>
			<view class="title">断针</view>
		</view>
		<view class="line-item"></view>
		<view v-for="(item,index) in processlogs" :key="index" @tap="openinfo" :data-stepid="index">
			<view class="uni-form-item uni-row">
				<view class="title">{{item.step_status}}</view>
				<view class="title">{{item.step_number}}</view>
				<view class="title">{{item.step_code}}</view>
				<view class="title">{{item.step_name}}</view>
				<view class="title">{{item.step_num_ok}}</view>
				<view class="title">{{item.step_num_ng}}</view>
				<view class="title">{{item.step_num_pm}}</view>
				<view class="title">{{item.step_num_scrap_a}}</view>
			</view>
			<view class="line-item"></view>
		</view>

	</view>
</template>

<script>
	export default {
		data() {
			return {
				workordernumber: '',
				subtitle: '一般贸易成品工单',
				productname: '',
				fulllength: '',
				specname: '',
				issuerecord: '',
				info: '',
				ymmachine: '',
				workorder_id: '',
				processlogs: [],
				ispb: 0, //1- to 品保
			};
		},
		onLoad(e) {
			console.log(e);
			this.workordernumber = e.workordernumber;
			this.ispb = e.ispb;
			let pages = getCurrentPages();
			let currPage = pages[pages.length - 1];
			currPage.data.refresh = "1";
		},
		onShow() {
			let pages = getCurrentPages();
			let currPage = pages[pages.length - 1];
			if (currPage.data.refresh == "1") {
				console.log("123456");
				this.getinfo();
			} else {
				console.log("asdf");
			}
			console.log("kjkhl");
			currPage.data.refresh = "0";
		},
		// 跳转到主页面
		onNavigationBarButtonTap(e) {
			uni.reLaunch({
				url: '/pages/mainlogin/mainlogin'
			});

		},
		methods: {
			openinfo: function(e) {
				var index = e.currentTarget.dataset.stepid;
				console.log(this.processlogs[index].step_operator);

				let detail = {
					processlog: this.processlogs[index],
					workordernumber: this.workordernumber,
					subtitle: this.subtitle,
					productname: this.productname,
					fulllength: this.fulllength,
					specname: this.specname,
					issuerecord: this.issuerecord,
					info: this.info,
					ymmachine: this.ymmachine,
					workorder_id: this.workorder_id
				}
				if (this.ispb == 0) {
					console.log("问我");
					console.log(JSON.stringify(detail));
					
					uni.navigateTo({
						url: '../processdetail/processdetail?detail=' + encodeURIComponent(JSON.stringify(detail))
					});
				} else {
					uni.navigateTo({
						url: '../pbupdatelog/pbupdatelog?detail=' + encodeURIComponent(JSON.stringify(detail))
					});
				}

			},
			getinfo: function() {
				console.log('getinfo ' + this.workordernumber);
				if (this.workordernumber.length < 1) {
					return;
				}

				uni.request({
					url: this.waiUrl + '/api/workorder/getinfo?',
					data: {
						"workordernumber": this.workordernumber
					},
					success: (res) => {
						console.log('request success', res)
						this.subtitle = res.data.data.subtitle;
						this.workordernumber = res.data.data.number;
						this.productname = res.data.data.productname;
						this.fulllength = res.data.data.fulllength;
						this.specname = res.data.data.specname;
						this.issuerecord = res.data.data.issuerecord;
						this.info = res.data.data.info;
						this.ymmachine = res.data.data.ymmachine;
						this.stepnames = res.data.data.stepnames;
						this.workorder_id = res.data.data.id;
						this.processtype_id = res.data.data.id;
						this.getprocessalllog();
					},
					fail: (err) => {
						console.log('request fail', err);
						uni.showModal({
							content: err.errMsg,
							showCancel: false
						});
					},
					complete: () => {

					}
				});
			},
			getprocessalllog: function() {
				console.log('getprocessalllog--' + this.workorder_id);
				uni.request({
					url: this.waiUrl + '/api/workorder/getprocessalllog?',
					data: {
						"workorder_id": this.workorder_id,
					},
					success: (res) => {
						this.processlogs = res.data.data;
						for (let i = 0; i < this.processlogs.length; i++) {
							this.processlogs[i].step_status = "N";
							if (this.processlogs[i].endtime > 0) {
								this.processlogs[i].step_status = "Y";
							}
						}
					},
					fail: (err) => {
						console.log('request fail2', err);
						processlogs = [];
						uni.showModal({
							content: err.errMsg,
							showCancel: false
						});
					},
					complete: () => {

					}
				});
			},
		}
	}
</script>

<style>
	button {
		margin-top: 30upx;
		margin-bottom: 30upx;
	}

	.title {
		font-size: 30upx;
		width: 350upx;
	}

	.line-item {
		height: 1upx;
		background: #999999;
		color: #FFF;
	}

	.title_blue {
		color: darkblue;
	}
</style>
